
<#include "/shared/style.ftl" />
<#include "/shared/javascript.ftl" />

<fieldset class="layui-elem-field layui-field-title" style="width: 45%;">
    <legend>修改用户信息</legend>
    <form class="layui-form" action="${baseUrlAdmin}/user/editInfo" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">昵称</label>
            <div class="layui-input-block">
                <input type="text" name="name" required  lay-verify="required" placeholder="请输入昵称" autocomplete="off" class="layui-input" value="${user.name}" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="text" name="email" required  lay-verify="required" placeholder="请输入邮箱" autocomplete="off" class="layui-input" value="${user.email}" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-block">
                <select name="type" lay-verify="required">
                    <#list types as type>
                        <#if type == user.type>
                            <option value="${type.value}" selected="selected">${type.text}</option>
                        <#else>
                            <option value="${type.value}">${type.text}</option>
                        </#if>
                    </#list>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <select name="status" lay-verify="required">
                    <#list statuses as status>
                        <#if status == user.status>
                            <option value="${status.value}" selected="selected">${status.text}</option>
                        <#else>
                            <option value="${status.value}">${status.text}</option>
                        </#if>
                    </#list>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formSubmit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</fieldset>

<script type="text/javascript">
    console.log('${user.type}')
    $('select[name="type"]').val('${user.type}');
    $('select[name="status"]').val('${user.status}');
    layui.use(['form'], function () {
        var form = layui.form, layer = layui.layer;
        //监听提交
        form.on('submit(formSubmit)', function (e) {
             layer.alert(JSON.stringify(e.field), { title: '最终的提交信息' });
            $.post('${baseUrlAdmin}/user/editInfo', e.field, function (data) {
                console.log(data);
                layer.confirm(data.message, { btn: ['确定'] }, function () {
                    if (data.code === 0) {
                        layuiManager.parentCloseTab(layuiTabConfig.userEditInfo.id);
                    }
                });

            });
            return false;
        });
    });
</script>
